﻿@using PersonalWebSite.Common
@{
    ViewBag.Title = "Hintea Dan Alexandru - Links";
    Layout = "~/Views/Shared/_Layout.cshtml";

    var previousNavigationItem = Html.NavigationManager().FetchPreviousHistoryItem() ?? ViewContext.RouteData;
}

<div id="UniverseHolderWrapper">
    <div class="hdunv-fixture"> 
        <div data-hdunv_type="Universe" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="1000" data-hdunv_h="100" data-hdunv_name="hD Universe" data-starfield_enabled="false" data-shootingstar_enabled="false">
            <div class="hdunv-content"></div>

            <div data-hdunv_type="Galaxy" data-hdunv_depth="0" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="1000" data-hdunv_h="120" data-hdunv_name="Header">
                <div data-hdunv_type="SolarSystem" data-hdunv_speed="0" data-hdunv_direction="cw" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="0" data-hdunv_h="0" data-hdunv_name="MainSection Top">
                    <div class="hdunv-content">
                        <div class="MetroTile"><div class="Content">
                            <h1>Links</h1>
                            <h2>Various links from the world wide web</h2>
                        </div></div>
                    </div>
                </div>
            </div>

            <div data-hdunv_type="Galaxy" data-hdunv_depth="0" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="1000" data-hdunv_h="50" data-hdunv_name="Header">
                <div data-hdunv_type="SolarSystem" data-hdunv_speed="0" data-hdunv_direction="cw" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="0" data-hdunv_h="0" data-hdunv_name="MainSection Top">
                    <div class="hdunv-content">
                        @{Html.RenderAction("Button", "Tiles", new { IconName = "Back", Tip = "Go Back", NavigateUrl = Url.Action((string)previousNavigationItem.Values["action"], (string)previousNavigationItem.Values["controller"], new { id = previousNavigationItem.Values["id"] }) });}
                    </div>
                </div>
                <div data-hdunv_type="SolarSystem" data-hdunv_speed="0" data-hdunv_direction="cw" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="0" data-hdunv_h="0" data-hdunv_name="MainSection Top">
                    <div class="hdunv-content">
                        @{Html.RenderAction("Button", "Tiles", new { IconName = "Home", Tip = "Go Home", NavigateUrl = Url.Action("Index", "Home") });}
                    </div>
                </div>
            </div>

            <!-- ko foreach: { data: LinksFeed.Items } -->
            <div data-hdunv_type="Galaxy" data-hdunv_depth="0" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="1000" data-hdunv_h="150" data-hdunv_name="Galaxy 1">
                <div data-hdunv_type="SolarSystem" data-hdunv_speed="0" data-hdunv_direction="cw" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="0" data-hdunv_h="0" data-hdunv_name="MainSection Top">
                    <div class="hdunv-content">
                        @{Html.RenderAction("Link", "Tiles");}
                    </div>
                </div>
            </div>
            <!-- /ko -->

        </div>
    </div>
</div>

<script type="text/javascript">

    $(window).resize(function () {
        $("#UniverseHolderWrapper").css("height", $(window).outerHeight());
    });
    $("#UniverseHolderWrapper").css("height", $(window).outerHeight());

    var PageViewModel = {
        LinksFeed: {},
        fetchCssUrlForItem: function (dataItem) {
            return "url('@Url.Content("~/Data/UrlScreenshots")/" + dataItem.Guid + ".png')";
        }
    };

    var fetchLinksAjaxIconId = -1; _hD.push(function () { fetchLinksAjaxIconId = AjaxIconToggle(true); });
    $.ajax('@Url.Action("FetchLinks", "Activity")', {
        complete: function (jqXHR, textStatus) {
            if (AjaxIconToggle)
                AjaxIconToggle(false, fetchLinksAjaxIconId);
            else
                _hD.push(function () { AjaxIconToggle(false, fetchLinksAjaxIconId); });
        },
        success: function (data, textStatus, jqXHR) {
            PageViewModel.LinksFeed = data;
            InitLinksTiles();
        },
        error: function (jqXHR, textStatus, errorThrown) {
            NotifierShow('Some error occured while trying to retrieve the links. I\'m very sorry for that, please try again by refreshing the page.', 'This page depends on some external resources. It may happen that these services are not available sometimes so again, sorry for the inconvenience and please try again to reload the page.');
        }
    });

    function InitLinksTiles() {
        ko.applyBindings(PageViewModel, $(".hdunv-fixture")[0]);

        var universe = new hDUnivSim("#UniverseHolderWrapper", new MetroStyleDrawer(false, 10), InPageHtmlFixture);
        universe.AlignHorizontal = Align.Horizontal.Center;
        universe.AlignVertical = Align.Vertical.Top;
        universe.InitHtml();

        InitMetroTilesColouringEffect();
    };

    
</script>